// components/chemical-factor/index.js

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    event: {
      type: Object,
      value: {},
      observer: 'eventChange'
    },
    dataSource: {
      type: Array,
      value: [],
      observer: 'setDataSource'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    ty: 100,
    source:  {}
  },

  /**
   * 组件的方法列表
   */
  methods: {
    showPopup() {
      this.setData({
        show: true
      });
    },
    onClose() {
      this.triggerEvent('onClose')
    },
    eventChange(event = {}) {
      this.setData({
        ty: (event.detail?.y || 0) + 20
      })
      const item = event.currentTarget?.dataset?.item;
      if (item) {
        const data = this.properties.dataSource.find(it => {
          return it.elementType === item.value
        })
        this.selectComponent('')
        if (data) {
          const expansionFactor = data.expansionFactor,
            fluxFactor = data.fluxFactor,
            tensionFactor = data.tensionFactor,
            name = item.name;
          this.setData({
            source: {
              expansionFactor,
              fluxFactor,
              tensionFactor,
              name
            }
          })
        }
      }
      
    },
    setDataSource(source) {
      //   const data = source.map(it => {
      //     const name = chemicalAlias[it.elementType],
      //       expansionFactor = it.expansionFactor,
      //       tensionFactor = it.tensionFactor;
      //     return {
      //       name,
      //       key: it.elementType,
      //       chemicalValue: '',
      //       expansionFactor,
      //       tensionFactor
      //     }
      //   })
      //  this.setData({
      //    source: data
      //  })
    }
  }
})